#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
int T,n,m,lize,v,dc[100010],vc[100010],ac[100010],p[100010],ldv[100010],rdv[100010],ans,cnt;
int c[100010];
pair<int,int>s[100010];
bool st[100010];
int idx;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        memset(s,0,sizeof s);
        memset(st,0,sizeof st);
        memset(c,0,sizeof c);
        idx=0;
        ans=cnt=0;
        scanf("%d%d%d%d",&n,&m,&lize,&v);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&dc[i],&vc[i],&ac[i]);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
        }
        for(int i=1;i<=n;i++){
            if(ac[i]==0){
                if(vc[i]>v){
                    int l1=1,r1=m;
                    while(l1<r1){
                        int mid=(l1+r1)>>1;
                        if(p[mid]<dc[i]){
                        l1=mid+1;
                    }else r1=mid;
                    ldv[i]=l1,rdv[i]=m;
                }
                }
                else ldv[i]=rdv[i]=-1;
            }
            if(ac[i]>0){
                if((p[m]-dc[i])*ac[i]*2+vc[i]*vc[i]<=v*v){
                    ldv[i]=rdv[i]=-1;
                    continue;
                }
                int l=1,r=m;
                while(l<r){
                    int mid=(l+r)>>1;
                    if(p[mid]<dc[i]){
                        l=mid+1;
                        continue;
                    }
                    if((p[mid]-dc[i])*ac[i]*2+vc[i]*vc[i]>v*v){
                        r=mid;
                    }else l=mid+1;
                }
                ldv[i]=l,rdv[i]=m;
            }
            if(ac[i]<0){
                if(vc[i]<=v){
                    ldv[i]=rdv[i]=-1;
                    continue;
                }
                int l1=1,r1=m;
                while(l1<r1){
                    int mid=(l1+r1)>>1;
                    if(p[mid]<dc[i]){
                        l1=mid+1;
                    }else r1=mid;
                }
                int j;
                for(j=l1;j<=m;j++){
                    if((p[j]-dc[i])*ac[i]*2+vc[i]*vc[i]<=v*v){
                        j--;
                        break;
                    }
                }
                ldv[i]=l1,rdv[i]=j;
            }
            if(ldv[i]>rdv[i]) ldv[i]=rdv[i]=-1;
            //cout<<ldv[i]<<" "<<rdv[i]<<endl;
            if(ldv[i]!=-1 && rdv[i]!=-1){
                ans++;
                c[ldv[i]]++,c[rdv[i]+1]--;
            }
        }
        cout<<ans<<" ";
        for(int i=1;i<=m;i++){
            s[i].x=s[i-1].x+c[i];
            s[i].y=i;
        }
        sort(s+1,s+1+m);
        reverse(s+1,s+1+m);
        for(int i=1;i<=m;i++){
            for(int j=1;j<=n;j++){
                if(st[j]) continue;
                if(ldv[j]<=s[i].y && rdv[j]>=s[i].y){
                    idx++;
                    st[j]=true;
                }
            }
            cnt++;
            if(idx==ans) break;
        }
        cout<<m-cnt<<endl;
    }
    return 0;
}
